// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package role

import (
	"audio-server/internal/model"
	"context"
	"database/sql"

	"audio-server/internal/svc"
	"audio-server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleUpdateLogic {
	return &RoleUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleUpdateLogic) RoleUpdate(req *types.RoleSaveReq) (resp bool, err error) {
	roleModel := model.NewSysRoleModel(l.svcCtx.Conn)
	role, err := roleModel.FindOne(l.ctx, int64(req.RoleId))
	if err != nil {
		return false, err
	}
	role.Name = req.Name
	role.Description = sql.NullString{String: req.Description, Valid: true}
	role.IsAdmin = int64(req.IsAdmin)
	err = roleModel.Update(l.ctx, role)
	return true, err
}
